import { ExecutionContext, createParamDecorator } from '@nestjs/common';
import { FastifyRequest } from 'fastify';
import { TenantEntity } from './tenant.entity';

/**
 * @description 获取当前登录用户信息, 并挂载到request上
 */
export const AuthTenant = createParamDecorator(async (data: any, ctx: ExecutionContext) => {
  const request = ctx.switchToHttp().getRequest<FastifyRequest>();
  const tenant = request['tenant'] ?? request.user?.tenant as TenantEntity;
  return tenant;
});
